package com.yanqu.road.server.cmd.systemgroup.newmonopolymkt;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.office.NewMonopolyMarketOfficeSeatInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketGroup;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_NEW_MONOPOLY_MARKET_SYN_USER_DATA_TO_CROSS, desc = "榷场同步玩家数据")
public class CrossNewMonopolyMarketSynUserDataCmd extends CrossAppointCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketSynUserDataToCrossReqMsg builder = NewMonopolyMarketProto.NewMonopolyMarketSynUserDataToCrossReqMsg.parseFrom(packet.getBytes());
        UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(packet.getPlayerId());
        if(userBaseInfo != null){
            userBaseInfo.setDecoration(builder.getDecoration());
            userBaseInfo.setTitleId(builder.getTitleId());
            userBaseInfo.setPrestige(builder.getPrestige());
        }
        CrossNewMonopolyMarketGroup monopolyMarket = CrossNewMonopolyMarketMgr.getMarket(groupId);
        if(monopolyMarket == null){
            return;
        }
        NewMonopolyMarketOfficeSeatInfo seatInfo = monopolyMarket.getMarketOffice().getSeatDataMap().get(builder.getCurPos());
        if(seatInfo != null && seatInfo.baseInfo.getPlayerId() == packet.getPlayerId()){
            seatInfo.baseInfo.setDecorationClass((byte)(builder.getDecorationClass()));
            seatInfo.baseInfo.setDecorationOverTime(builder.getDecorationOverTime());
            synchronized (monopolyMarket.getMarketOffice().updateAndAddSeatInfoSet){
                monopolyMarket.getMarketOffice().updateAndAddSeatInfoSet.add(seatInfo);
            }
        }

    }

    @Override
    public void sendData() {

    }
}
